package com.gel.shortLink.admin.controller;

import com.gel.shortLink.admin.common.enums.UserErrorCodeEnum;
import com.gel.shortLink.admin.convention.exception.ClientException;
import com.gel.shortLink.admin.convention.result.Result;
import com.gel.shortLink.admin.convention.result.Results;
import com.gel.shortLink.admin.dto.req.UserLoginRepDTO;
import com.gel.shortLink.admin.dto.req.UserReqDTO;
import com.gel.shortLink.admin.dto.req.UserUpdateRepDTO;
import com.gel.shortLink.admin.dto.resp.UserLoginRespDTO;
import com.gel.shortLink.admin.dto.resp.UserRespDTO;
import com.gel.shortLink.admin.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/short-link/admin/user")
@RequiredArgsConstructor
public class UserController {
    private final UserService userService;


    /*根据用户名获取用户*/
    @GetMapping("/{username}")
    public Result<UserRespDTO> getUserByUserName (@PathVariable("username") String username){
        UserRespDTO user = userService.getUserByUsername(username);
        return Results.success(user);

    }
    /*查看用户名是否存在*/

    @GetMapping("/hasUserName")
    public Result<Boolean> hasUserName (String  username){
        return Results.success(userService.hasUserName(username));
    }
    /*用户注册*/
    @PostMapping("/register")
    public Result<Void> register (@RequestBody UserReqDTO requestParam){

        userService.register(requestParam);
        return Results.success();
    }
    /*用户登录*/
    @PostMapping("/login")
    public Result<UserLoginRespDTO> login (@RequestBody UserLoginRepDTO requestParam){
        return Results.success(userService.login(requestParam));
    }
    /*检查用户是否已经登录*/
    @GetMapping("/checkLogin")
    public Result<Boolean> checkLogin (String username,String token){
        Boolean checkLogin = userService.checkLogin(username, token);
        return Results.success(checkLogin);
    }
    /*用户退出登录*/
    @DeleteMapping("/logout")
    public Result<Void> logout (String username,String token){
        userService.logout(username,token);
        return Results.success();
    }
    /*用户信息更改*/
    @PutMapping("/update")
    public Result<Void> update (@RequestBody UserUpdateRepDTO requestParam){
        userService.update(requestParam);
        return Results.success();
    }




}
